#1 导入依赖
import requests
from lxml import etree

#2 发送请求和获取响应
html = requests.get('https://www.dushu.com/lianzai/')
html.encoding='utf-8'
html_text2 = html.text

#2.2 创建节点树的第二种方式：如果爬取的html文本如何转换为节点树?
# 解析html文件，返回一个节点树的对象
html_selector = etree.HTML(html_text2)

#3 获取根节点html的元素
bookname=html_selector.xpath("/html/body/div[5]/div/div[2]/div[3]/ul/li/div/h3/a/text()")
print(bookname)
imgs=html_selector.xpath("/html/body/div[5]/div/div[2]/div[3]/ul/li[1]/div/div/a/img/@data-original")
print(imgs)

